﻿#include "theopendevicediscoverlistmodel.h"
#include "Sington.h"
void TheOpenDeviceDiscoverListModel::infoAppending(QString str)
{
    m_data.append(MyData(str));
}

TheOpenDeviceDiscoverListModel *TheOpenDeviceDiscoverListModel::instance()
{
    return Sington<TheOpenDeviceDiscoverListModel>::getInstance();
}

TheOpenDeviceDiscoverListModel::TheOpenDeviceDiscoverListModel(QObject *parent)
    : QAbstractListModel(parent)
{
}

QHash<int, QByteArray> TheOpenDeviceDiscoverListModel::roleNames() const
{
    QHash<int,QByteArray> roles;
    roles.insert(Content::Theipaddandport,"c_ipAddressandport");//字符串是Qml调用
    return roles;
}

//元素的个数或者说是model的长度/大小
int TheOpenDeviceDiscoverListModel::rowCount(const QModelIndex &parent) const
{
    // For list models only the root node (an invalid parent) should return the list's size. For all
    // other (valid) parents, rowCount() should return 0 so that it does not become a tree model.
    if (parent.isValid())
        return 0;
    return m_data.count();

    // FIXME: Implement me!
}

QVariant TheOpenDeviceDiscoverListModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid())
        return QVariant();
    QVariant var;
    switch(role)
    {
    case Content::Theipaddandport:
        var = QVariant::fromValue(m_data[index.row()].m_ipaddandport);
        break;
    default:
        break;
    }
    return var;

}
